package com.seedwill.common.persistence;

import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;

public class GenericFilterContainer<T> implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5580530401698954786L;
	/**
	 * 是否分页
	 */
	private boolean pagnation;
	
	public boolean isPagnation() {
		return pagnation;
	}

	public void setPagnation(boolean pagnation) {
		this.pagnation = pagnation;
	}
	
	protected Class<T> entityClz;
	
	@SuppressWarnings("unchecked")
	public GenericFilterContainer() {
		super();
		this.entityClz = (Class<T>) ((ParameterizedType) this.getClass()
				.getGenericSuperclass()).getActualTypeArguments()[0];
	}
	/**
	 * 过滤器LIST
	 */
	private List<Filter> filterList;

	public List<Filter> getFilterList() {
		return filterList;
	}

	public void setFilterList(List<Filter> filterList) {
		this.filterList = filterList;
	}
	
	public void addFilter(Filter f){
		prepareFilterList();
		filterList.add(f);
	}

	private void prepareFilterList() {
		if(null == filterList){
			filterList = new ArrayList<Filter>();
		}
	}
	
	/**
	 * 每页记录数目
	 */
	private int pageSize;
	
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * pagnation为TRUE的时候请求的页码
	 */
	private int requestPageNo;
	
	public int getRequestPageNo() {
		return requestPageNo;
	}

	public void setRequestPageNo(int requestPageNo) {
		this.requestPageNo = requestPageNo;
	}
	
	/**
	 * 排序
	 */
	private List<OrderBy> orderByList;
	
	public List<OrderBy> getOrderByList() {
		return orderByList;
	}

	public void setOrderByList(List<OrderBy> orderByList) {
		this.orderByList = orderByList;
	}

	/**
	 * 
	 */
	private void prepareOrderByList() {
		if(null == orderByList){
			orderByList = new ArrayList<OrderBy>();
		}
	}
	
	/**
	 * @param f
	 */
	public void addFilter(OrderBy f){
		prepareOrderByList();
		orderByList.add(f);
	}

	public Class<T> getEntityClz() {
		return entityClz;
	}

//	public void setEntityClz(Class<T> entityClz) {
//		this.entityClz = entityClz;
//	}
}
